import { Component, OnInit } from '@angular/core';

declare var form: any;

@Component({
  templateUrl: './report.dictionary.component.html'
})
export class ReportDictionaryComponent implements OnInit {

  // 表单
  fs: any = null;
  // 字典
  public administrativeDic: any = null;
  public metadataDic: any = null;

  constructor() {
    this.fs = new form.FormSimpleService('reportdictionary', {
      orderObject: { order: 0 },
      keyField: 'id',
      randomFields: ['id']
    });
    this.fs.loadData(true);
    
    this.administrativeDic = new form.DictionaryService('p_administrative', this.filter);
    this.administrativeDic.loadAll();

    this.metadataDic = new form.DictionaryService('f_metadata_directory', this.filter);
    this.metadataDic.loadAll();

  }

  ngOnInit() {
  }

  filter(data) {
    if (data) {
      const ri = [];
      for (let i = data.length - 1; i >= 0; i--) {
        const e = data[i];
        if (e.info && e.info === '2') {
          ri.push(i);
        }
      }
      ri.forEach((j) => {
        data.splice(j, 1);
      });
    }
    return data;
  }
}
